package edu.hawaii.myisern.brown.action;

import java.util.ArrayList;
import java.util.List;
//import java.util.Map;
import edu.hawaii.myisern.brown.model.MyIsernModel;
import net.sourceforge.stripes.action.DontValidate;
import net.sourceforge.stripes.action.RedirectResolution;
import net.sourceforge.stripes.action.Resolution;
import net.sourceforge.stripes.validation.Validate;

/**
 * New Organization Action Bean.
 * 
 * @author rcox
 * 
 */
public class EditOrganizationActionBean extends MyIsernActionBean {

  @Validate(required = true)
  private String name;
  private String contact;
  private String homePage;
  private String country;
  private List<String> affiliatedResearchers = new ArrayList<String>();
  private String researchDescription;
  private List<String> researchKeywords = new ArrayList<String>();
  private String type;
  
  private String newAffiliatedResearcher;
  private String newResearchKeyword;

  /**
   * Get researcher key words string.
   * @return the researchKeywordsStr
   */
  public synchronized String getNewResearchKeyword() {
    return newResearchKeyword;
  }

  /**
   * Set research key words string.
   * @param researchKeywordsStr the researchKeywordsStr to set
   */
  public synchronized void setNewResearchKeyword(String researchKeywordsStr) {
    this.newResearchKeyword = researchKeywordsStr;
  }

  /**
   * Get affiliated researchers string.
   * @return the affiliatedResearchersStr
   */
  public synchronized String getNewAffiliatedResearcher() {
    return newAffiliatedResearcher;
  }

  /**
   * Set affiliated researchers string.
   * @param newAffiliatedResearcher the affiliatedResearchersStr to set
   */
  public synchronized void setNewAffiliatedResearcher(String newAffiliatedResearcher) {
    this.newAffiliatedResearcher = newAffiliatedResearcher;
  }
 
  /**
   * Gets the contact.
   * 
   * @return the contact
   */
  public String getContact() {
    return contact;
  }

  /**
   * Sets the contact.
   * 
   * @param contact the contact to set
   */
  public void setContact(String contact) {
    this.contact = contact;
  }

  /**
   * Gets the name.
   * 
   * @return the name
   */
  public String getName() {
    return name;
  }

  /**
   * Sets the name.
   * 
   * @param name the name to set
   */
  public void setName(String name) {
    this.name = name;
  }

  /**
   * Get the home page.
   * 
   * @return the homePage
   */
  public String getHomePage() {
    return homePage;
  }

  /**
   * Sets the home page.
   * 
   * @param homePage the homePage to set
   */
  public void setHomePage(String homePage) {
    this.homePage = homePage;
  }

  /**
   * Gets the country.
   * 
   * @return the country
   */
  public String getCountry() {
    return country;
  }

  /**
   * Sets the country.
   * 
   * @param country the country to set
   */
  public void setCountry(String country) {
    this.country = country;
  }

  /**
   * Gets the affiliated researchers.
   * 
   * @return the affiliatedResearchers
   */
  public List<String> getAffiliatedResearchers() {
    return affiliatedResearchers;
  }

  /**
   * Sets the affiliated researchers.
   * 
   * @param affiliatedResearchers the affiliatedResearchers to set
   */
  public void setAffiliatedResearchers(List<String> affiliatedResearchers) {
    this.affiliatedResearchers = affiliatedResearchers;
  }

  /**
   * Get the reserach description.
   * 
   * @return the researchDescription
   */
  public String getResearchDescription() {
    return researchDescription;
  }

  /**
   * Set the reserch description.
   * 
   * @param researchDescription the researchDescription to set
   */
  public void setResearchDescription(String researchDescription) {
    this.researchDescription = researchDescription;
  }

  /**
   * Get the research keywords.
   * 
   * @return the researchKeywords
   */
  public List<String> getResearchKeywords() {
    return researchKeywords;
  }

  /**
   * Set the research keywords.
   * 
   * @param researchKeywords the researchKeywords to set
   */
  public void setResearchKeywords(List<String> researchKeywords) {
    this.researchKeywords = researchKeywords;
  }

  /**
   * Get type.
   * 
   * @return the type
   */
  public String getType() {
    return type;
  }

  /**
   * Set type.
   * 
   * @param type the type to set
   */
  public void setType(String type) {
    this.type = type;
  }

  /**
   * Loads a record on to the form ready for editing.
   * 
   * @return resolution of next page.
   */
  @DontValidate
  public Resolution preEdit() {
    if (this.name != null) {
      this.model.fillOrganization(this, MyIsernModel.makeId(this.name));
    }
    return new RedirectResolution("/editOrganization.jsp").flash(this);
  }


  
  /**
   * Save the record.
   * 
   * @return resolution to main menu.
   */
  public Resolution save() {
    //this.affiliatedResearchers.add(this.);
    include(this.newResearchKeyword, this.researchKeywords);
    include(this.newAffiliatedResearcher, this.affiliatedResearchers);
    this.newAffiliatedResearcher = "";
    this.newResearchKeyword = "";
    this.model.storeOrganization(this);
    saveModel(); 
    return new RedirectResolution("/editOrganization.jsp").flash(this);
  }

  /**
   * Cancel and return to main menu.
   * 
   * @return resolution to main menu.
   */
  @DontValidate
  public Resolution cancel() {
    return new RedirectResolution("/mainMenu.jsp");
  }

}
